﻿using Microsoft.Extensions.Logging;
using NuGet.Protocol.Core.Types;

namespace WebAPI.Common
{
    public class LogUtility : ILogUtility
    {
        ILogger _logger;

        public void WriteMessage(string message)
        {
            Console.WriteLine($"MyDependency.WriteMessage Message: {message}");
        }

        /// <summary>
        /// 写日志
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public void Info(string message)
        {
            _logger.LogInformation(message);
        }

        /// <summary>
        /// 写错误日志
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        public void Error(Exception ex, string message = null)
        {
            if (string.IsNullOrEmpty(message))
                message = ex.Message;

            _logger.LogError(message, ex);
        }

        /// <summary>
        /// 写错误日志
        /// </summary>
        /// <param name="message"></param>
        public void Error(string message)
        {
            _logger.LogError(message);
        }
    }
}
